package gui.commands.classDiagramCommands;

import data.DataVector;
import data.classDiagram.Entity;
import data.classDiagram.Member;
import gui.commands.ICommand;

/**
 * User: Szymon Kudzia
 * Date: 10.05.13
 * Time: 14:56
 */
public class AddNewMemberCommand implements ICommand {
	protected Entity entity;
	protected Member member;

	protected String name;
	protected String unknown;
	protected String type;
	protected String defaultValue;
	protected String minMaxValue;
	protected boolean isStatic;
	protected String visibility;

	public AddNewMemberCommand(String name, String unknown, String type, String defaultValue,
	                           String minMaxValue, boolean isStatic, String visibility) {
		this.name = name;
		this.unknown = unknown;
		this.type = type;
		this.defaultValue = defaultValue;
		this.minMaxValue = minMaxValue;
		this.isStatic = isStatic;
		this.visibility = visibility;
	}

	@Override
	public void execute() {
		member = new Member();
		member.setName(name);
		member.setType(type != null ? type : unknown);
		member.setDefaultValue(defaultValue);
		member.setMinMax(minMaxValue);
		member.setStatic(isStatic);
		member.setVisibility(visibility);

		entity = DataVector.getInstance().getActiveEntity();
		DataVector.getInstance().addMemberToActiveEntity(member);
	}

	@Override
	public void undo() {
		entity.getMembers().remove(member);
		DataVector.getInstance().refresh();
	}

	@Override
	public void redo() {
		entity.addMember(member);
		DataVector.getInstance().refresh();
	}
}
